package com.genesis.yunnanji.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.genesis.yunnanji.R;
import com.genesis.yunnanji.activity.Login;
import com.genesis.yunnanji.activity.Pavilion;
import com.genesis.yunnanji.activity.StoreWeb;
import com.genesis.yunnanji.config.GenesisApiConfig;
import com.genesis.yunnanji.utils.GenesisUtils;

/**
 * Created by Administrator on 2017/11/7.
 */

public class HomeCate2 extends Fragment {
    private View view;
    private LinearLayout pavilion;
    private LinearLayout store;
    private GenesisUtils genesisUtils;
    private Intent intent;

    public static HomeCate2 newInstance(String param) {
        HomeCate2 obj = new HomeCate2();
        Bundle bundle = new Bundle();
        bundle.putString("args1", param);
        obj.setArguments(bundle);
        return obj;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (view == null) {
            view = this.getActivity().getLayoutInflater().inflate(R.layout.fragment_homepage_cate2, null);
            pavilion = (LinearLayout) view.findViewById(R.id.homepage_cate_pavilion);
            store = (LinearLayout) view.findViewById(R.id.homepage_cate_store);
            genesisUtils = GenesisUtils.getIntance();
            initView();
        } else {
            ViewGroup parent = (ViewGroup) view.getParent();
            if (parent != null) {
                parent.removeView(view);
            }
        }
        setUpView();
        return view;
    }

    protected void initView() {

    }

    protected void setUpView() {
        pavilion.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                intent = new Intent(HomeCate2.this.getContext(), Pavilion.class);
                startActivity(intent);
            }
        });
        store.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (genesisUtils.isLogin()) {
                    intent = new Intent(HomeCate2.this.getContext(), StoreWeb.class);
                    intent.putExtra("url", GenesisApiConfig.HOST + "/Mall/Index/index.html");
                    startActivity(intent);
                } else {
                    intent = new Intent(HomeCate2.this.getContext(), Login.class);
                    startActivity(intent);
                }
            }
        });
    }
}
